package com.baizhi.cmfz.exception;

import com.baizhi.cmfz.app.common.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ExceptionHandler 配合 @ControllerAdvice
 * @RestControllerAdvice 声明要捕获哪个异常
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public R runtimeExceptionHandler(Exception e){
        log.error("后台异常，异常信息为：{}",e.getStackTrace());
        return R.error(500, "后台异常 请联系管理员");
    }

    @ExceptionHandler(AuthorizationException.class)
    public R authorizationExceptionHandler(){
        log.warn("没有权限");
        return R.error(500, "该用户没有权限");
    }
}
